package cn.xuguowen.user.designPatten.chain_of_responsibility.article.common;

import cn.hutool.core.collection.CollUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * ClassName: ArticleFilterFactory
 * Package: cn.xuguowen.user.designPatten.chain_of_responsibility.article.common
 * Description: 文章过滤器工厂
 *
 * @Author 徐国文
 * @Create 2023/6/3 9:02
 * @Version 1.0
 */
public class ArticleFilterFactory {

    public static List<ArticleFilter> createArticleFilter(List<ArticleFilterEnum> articleFilterEnums) {
        List<ArticleFilter> articleFilters = new ArrayList<>();

        if (!CollUtil.isEmpty(articleFilterEnums)) {
            articleFilters = articleFilterEnums.stream().map(x -> {
                ArticleFilter filter = ArticleFilterFactory.createFilter(x);
                return filter;
            }).collect(Collectors.toList());
        }

        return articleFilters;
    }

    public static ArticleFilter createFilter(ArticleFilterEnum articleFilterEnum) {
        ArticleFilter articleFilter = null;

        // switch中也是可以使用枚举的
        switch (articleFilterEnum) {
            case WORD_COUNT:
                articleFilter = new WordCountFilter();
                break;
            default:
                break;
        }

        return articleFilter;
    }
}
